package com.ruoyi.web.controller.gas;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.gas.domain.GasCompany;
import com.ruoyi.gas.service.IGasCompanyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 企业信息Controller
 *
 * @author ruoyi
 * @date 2024-01-18
 */
@RestController
@RequestMapping("/gas/company")
public class GasCompanyController extends BaseController
{
    @Autowired
    private IGasCompanyService gasCompanyService;

    /**
     * 查询企业信息列表
     */
    @PreAuthorize("@ss.hasPermi('gas:company:list')")
    @GetMapping("/list")
    public TableDataInfo list(GasCompany gasCompany)
    {
        startPage();
        List<GasCompany> list = gasCompanyService.selectGasCompanyList(gasCompany);
        return getDataTable(list);
    }

    /**
     * 导出企业信息列表
     */
    @PreAuthorize("@ss.hasPermi('gas:company:export')")
    @Log(title = "企业信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GasCompany gasCompany)
    {
        List<GasCompany> list = gasCompanyService.selectGasCompanyList(gasCompany);
        ExcelUtil<GasCompany> util = new ExcelUtil<GasCompany>(GasCompany.class);
        util.exportExcel(response, list, "企业信息数据");
    }

    /**
     * 获取企业信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('gas:company:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(gasCompanyService.selectGasCompanyById(id));
    }

    /**
     * 新增企业信息
     */
    @PreAuthorize("@ss.hasPermi('gas:company:add')")
    @Log(title = "企业信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GasCompany gasCompany)
    {
        return toAjax(gasCompanyService.insertGasCompany(gasCompany));
    }

    /**
     * 修改企业信息
     */
    @PreAuthorize("@ss.hasPermi('gas:company:edit')")
    @Log(title = "企业信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GasCompany gasCompany)
    {
        return toAjax(gasCompanyService.updateGasCompany(gasCompany));
    }

    /**
     * 删除企业信息
     */
    @PreAuthorize("@ss.hasPermi('gas:company:remove')")
    @Log(title = "企业信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gasCompanyService.deleteGasCompanyByIds(ids));
    }

    /**
     * 查询企业集合（id和名称）
     * @return
     */
    @GetMapping("/selectCompanyList")
    public AjaxResult selectCompanyList(){
        return AjaxResult.success(gasCompanyService.selectCompanyList());
    }
}
